#include<stdio.h>
#include<stdlib.h>

static char *reStr(const char *str);

int main()
{
	char str[] = "Good morning";
	printf("The string is\n");
	printf("%s\n", str);
	printf("The reversed string is\n");
	char *p1 = reStr(str);
	if(p1)
	{
	    printf("%s\n", p1);
	    free(p1);
	}
	return 0;
}

static char *reStr(const char *str)
{
	int strLen = strlen(str);
	char *p1 = (char*)str + strLen - 1;
	char *p2 = (char*)malloc(strLen + 1);
	char *p3 = p2;

    if(p3 == NULL) return NULL;
	memset(p2, 0, strLen+1);
	for(; strLen > 0; p3++, p1--, strLen--)
		*p3 = *p1;
	return p2;
}
